<?php
/**
 * User Profile controller
 * 
 * @author Joseph Chereshnovsky <joseph.chereshnovsky@gmail.com>
 */
class User_ProfileController extends Wise_Controller_Abstract
{
	/**
	 * Show user summary page
	 */
	public function indexAction()
	{
		
	}
	
	public function optionsAction()
	{
		$locale = Zend_Registry::get('Zend_Locale');
		$req = $this->getRequest();
		
		if ($req->isPost()) {
			
			$this->User->locale = $req->getPost('interface_language');
			
			/**
			 * After locale was changed we need to rebuild all locale related data 
			 * for now wee need only static session values needs to be changed
			 * source_lang_title, target_lang_title
			 */
			$sourceLangCode = $this->User->source_lang_code;
			$this->User->source_lang_title = mb_ucfirst($locale->getLanguageTranslation($sourceLangCode, $this->User->locale));
			
			$targetLangCode = $this->User->target_lang_code;
			$this->User->target_lang_title = mb_ucfirst($locale->getLanguageTranslation($targetLangCode, $this->User->locale));
			
			/**
			 * Redirect to "Options" page
			 */
			$this->_redirect('/user/profile/options');

		}
		
		$tr = Zend_Registry::get('Zend_Translate');
		$availLangCodes = $tr->getList();
		
		$langIndex = array();
		foreach($availLangCodes as $langCode) {
			// $langIndex[$langCode] = mb_ucfirst($locale->getLanguageTranslation($langCode));
			// BUG FIX: doesn't use default locale, so we need to provide locale directly
			$langIndex[$langCode] = mb_ucfirst($locale->getLanguageTranslation($langCode, $langCode));
		}
		
		$this->view->langs = $langIndex;
	}
}